package com.accp.vehiclecare.action.xzhaction;

import com.accp.vehiclecare.biz.xzhbiz.ArtisanGradeBiz;
import com.accp.vehiclecare.vo.xzhvo.ArtisanGradeVO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/ArtisanGradeAction")
public class ArtisanGradeAction {
    @Autowired
    private ArtisanGradeBiz artisanGradeBiz;

    /**
     * 查询技工星级
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/queryArtisanGrade/{pageNum}/{pageSize}")
    public PageInfo<ArtisanGradeVO> queryArtisanGrade(@PathVariable Integer pageNum,@PathVariable Integer pageSize){
        return artisanGradeBiz.queryArtisanGrade(pageNum,pageSize);
    }

    /**
     * 新增技工星级
     * @param artisanGradeVO
     * @return
     */
    @PostMapping ("/addArtisanGrade")
    public Map<String,Object> addArtisanGrade(@RequestBody ArtisanGradeVO artisanGradeVO){
        Map<String,Object>map = new HashMap<String,Object>();
        boolean bol = artisanGradeBiz.addArtisanGrade(artisanGradeVO);
        if (bol){
            map.put("code","200");
            map.put("msg","ok");
        }else{
            map.put("code","300");
            map.put("msg","on");
        }
        return map;
    }

    /**
     * 修改技工星级
     * @param artisanGradeVO
     * @return
     */
    @PutMapping("/amendArtisanGrade")
    public Map<String,Object> amendArtisanGrade(@RequestBody ArtisanGradeVO artisanGradeVO){
        boolean bol = artisanGradeBiz.amendArtisanGrade(artisanGradeVO);
        Map<String,Object>map = new HashMap<String,Object>();
        if(bol){
            map.put("code","200");
            map.put("msg","ok");
        }else{
            map.put("code","300");
            map.put("msg","on");
        }
        return map;
    }

    /**
     * 删除技工星级
     * @param id
     * @return
     */
    @DeleteMapping("/removeArtisanGrade/{id}")
    public Map<String,Object> removeArtisanGrade(@PathVariable Integer id){
        Map<String,Object>map = new HashMap<String,Object>();
        boolean bol = artisanGradeBiz.removeArtisanGrade(id);
        if(bol){
            map.put("code","200");
            map.put("msg","ok");
        }else{
            map.put("code","300");
            map.put("msg","on");
        }
        return map;
    }

    /**
     * 查询星级
     * @return
     */
    @GetMapping("/queryArtisanGradeVO")
    public List<ArtisanGradeVO> queryArtisanGradeVO(){
        return artisanGradeBiz.queryArtisanGradeVO();
    }

}
